package com.download.controller;

import com.download.service.DownloadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/download")
public class DownloadController {

    @Autowired
    private DownloadService downloadService;

    /**
     * 下载单个文件
     * @param filePath 文件路径
     * @throws Exception
     */
    @GetMapping("/filePath")
    public void downloadFile(String filePath) throws Exception {
        downloadService.downloadFile(filePath);
    }

    /**
     * 打包下载文件
     * @param filePaths 文件路径英文,分割
     * @param currentPath 当前所在路径
     * @throws Exception
     */
    @GetMapping("/filePaths")
    public void downloadFiles(String filePaths, String currentPath) throws Exception {
        String[] split = filePaths.split(",");
        List<String> list = Arrays.asList(split);
        downloadService.downloadZip(list,currentPath);
    }

}
